﻿namespace Bowlus.Common
{
    using System.Linq;

    public class ServiceManagementSettings
    {
        public string Subscription { get; set; }

        public string Thumbprint { get; set; }

        public string ServiceName { get; set; }

        public string DeploymentSlot { get; set; }

        public static ServiceManagementSettings Parse(string settingString)
        {
            // TODO: We can clean this up a bit and maybe use reflection
            //      Need to include assertions on the configuration string
            var settings = new ServiceManagementSettings();
            var setting = settingString.Split(';');

            foreach (var settingval in setting.Select(s => s.Split('=')))
            {
                switch (settingval[0])
                {
                    case "subscription":
                        settings.Subscription = settingval[1];
                        break;
                    case "deploymentslot":
                        settings.DeploymentSlot = settingval[1];
                        break;
                    case "thumbprint":
                        settings.Thumbprint = settingval[1];
                        break;
                    case "servicename":
                        settings.ServiceName = settingval[1];
                        break;
                }
            }

            return settings;
        }
    }
}
